package tld.course.lesson0 
{
	import flash.display.Graphics;
	import flash.display.Shape;
	import flash.geom.Point;
	
	/**
	 * The class for drawing circles programmatically.
	 * 
	 * @author wvxvw
	 * 
	 * @playerversion 10.0
	 */
	public class Circle extends Shape
	{
		public const direction:Point = new Point();
		
		// Declaring private variables. Unlike constants, variables may contain
		// a reference to different objects during the program life time.
		private var _radius:uint;
		private var _color:uint;
		
		public function Circle(radius:uint = 0, color:uint = 0)
		{
			super();
			this._radius = radius;
			this._color = color;
			if (radius) this.draw();
		}
		
		public function bounceY():uint
		{
			// Using a compound operator (an operator created by putting 
			// together two other operators) multiply assign. The operator will,
			// obviously, first multiply by the second operand and then assign
			// to the first operand. This operator exposes a restriction on it's
			// first operand - it has to be of a reference type because an
			// expression `10 *= 10' is invalid since you cannot assign to 
			// constant `10'.
			this.direction.y *= -1;
			return super.y + this.direction.y;
		}
		
		public function bounceX():uint
		{
			this.direction.x *= -1;
			return super.x + this.direction.x;
		}
		
		private function draw():void
		{
			var canvas:Graphics = super.graphics;
			canvas.clear();
			canvas.beginFill(this._color);
			canvas.drawCircle(0, 0, this._radius);
			canvas.endFill();
		}
	}
}